
private void initUI() throws MalformedURLException {
    setTitle("首页 - 二次元角色图鉴");
    setSize(800, 600);
    setLocationRelativeTo(null); // 居中显示
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // 主面板
    JPanel mainPanel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.insets = new Insets(10, 10, 10, 10); // 添加边距

    // 顶部标题和搜索框
    JPanel headerPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JLabel titleLabel = new JLabel("动漫世界");
    titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
    headerPanel.add(titleLabel);

    JTextField searchField = new JTextField(20);
    JButton searchButton = new JButton("搜索角色");
    headerPanel.add(searchField);
    headerPanel.add(searchButton);

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(headerPanel, gbc);

    // 热度 TOP3 角色
    JPanel top3Panel = new JPanel(new GridLayout(1, 3, 20, 20)); // 三列布局，间距为 20
    top3Panel.setBorder(BorderFactory.createTitledBorder("热度 TOP3 角色"));

    // 假数据
    String[] names = {"艾伦", "佐助", "阿斯兰"};
    String[] descriptions = {"7赞", "2赞", "1赞"};
    ImageIcon[] images = {
            new ImageIcon(new URL("https://web-rose25.oss-cn-beijing.aliyuncs.com/08145663-36a9-489d-831b-c8e69ebf8e41.jpg")),
            new ImageIcon("path/to/sasuke.jpg"),
            new ImageIcon("path/to/aslan.jpg")
    };

    for (int i = 0; i < 3; i++) {
        JLabel nameLabel = new JLabel(names[i]);
        JLabel descLabel = new JLabel(descriptions[i]);
        JLabel imageLabel = new JLabel(images[i]);

        JPanel characterPanel = new JPanel(new BorderLayout());
        characterPanel.setBorder(BorderFactory.createLineBorder(Color.GRAY)); // 添加边框
        characterPanel.add(imageLabel, BorderLayout.CENTER);

        // 添加编号标签
        JLabel numberLabel = new JLabel((i + 1) + "");
        numberLabel.setFont(new Font("Arial", Font.BOLD, 18));
        numberLabel.setForeground(Color.ORANGE);
        characterPanel.add(numberLabel, BorderLayout.NORTH);

        // 名称和描述放在一个面板中
        JPanel infoPanel = new JPanel(new BorderLayout());
        infoPanel.add(nameLabel, BorderLayout.NORTH);
        infoPanel.add(descLabel, BorderLayout.SOUTH);
        characterPanel.add(infoPanel, BorderLayout.SOUTH);

        top3Panel.add(characterPanel);
    }

    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.gridwidth = 2;
    gbc.fill = GridBagConstraints.BOTH;
    mainPanel.add(top3Panel, gbc);

    // 今日幸运之星
    JPanel luckyPanel = new JPanel(new BorderLayout());
    luckyPanel.setBorder(BorderFactory.createTitledBorder("今日幸运之星"));

    JLabel luckyNameLabel = new JLabel("艾伦");
    JLabel luckyDescLabel = new JLabel("海的那边是敌人");

    // 缩放图片以适应面板大小
    ImageIcon luckyImageIcon = images[0];
    Image scaledImage = luckyImageIcon.getImage().getScaledInstance(200, 200, Image.SCALE_SMOOTH);
    JLabel luckyImageLabel = new JLabel(new ImageIcon(scaledImage));

    // 添加星标图标
    JLabel starLabel = new JLabel("\u2605"); // 星标 Unicode
    starLabel.setFont(new Font("Arial", Font.BOLD, 24));
    starLabel.setForeground(Color.ORANGE);

    JPanel luckyContentPanel = new JPanel(new BorderLayout());
    luckyContentPanel.add(starLabel, BorderLayout.WEST);
    luckyContentPanel.add(luckyImageLabel, BorderLayout.CENTER);

    JPanel infoPanel = new JPanel(new BorderLayout());
    infoPanel.add(luckyNameLabel, BorderLayout.NORTH);
    infoPanel.add(luckyDescLabel, BorderLayout.SOUTH);
    luckyContentPanel.add(infoPanel, BorderLayout.EAST);

    luckyPanel.add(luckyContentPanel, BorderLayout.CENTER);

    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.gridwidth = 1;
    gbc.fill = GridBagConstraints.BOTH;
    mainPanel.add(luckyPanel, gbc);

    // 热门角色（简化版）
    JPanel hotPanel = new JPanel();
    hotPanel.setLayout(new BoxLayout(hotPanel, BoxLayout.Y_AXIS));
    hotPanel.setBorder(BorderFactory.createTitledBorder("热门角色"));

    for (int i = 0; i < 3; i++) {
        JLabel nameLabel = new JLabel(names[i]);
        JLabel descLabel = new JLabel(descriptions[i]);
        JLabel imageLabel = new JLabel(images[i]);

        JPanel characterPanel = new JPanel(new BorderLayout());
        characterPanel.setBorder(BorderFactory.createLineBorder(Color.GRAY)); // 添加边框
        characterPanel.add(imageLabel, BorderLayout.WEST);

        JPanel infoPanelTmp = new JPanel(new BorderLayout());
        infoPanelTmp.add(nameLabel, BorderLayout.NORTH);
        infoPanelTmp.add(descLabel, BorderLayout.SOUTH);
        characterPanel.add(infoPanelTmp, BorderLayout.CENTER);

        hotPanel.add(characterPanel);
        hotPanel.add(Box.createRigidArea(new Dimension(0, 10))); // 添加间隔
    }

    gbc.gridx = 1;
    gbc.gridy = 2;
    gbc.gridwidth = 1;
    gbc.fill = GridBagConstraints.BOTH;
    mainPanel.add(hotPanel, gbc);

    // 设置主面板
    setContentPane(mainPanel);

    // 使用 FlatLaf 主题
    try {
        UIManager.setLookAndFeel("com.formdev.flatlaf.FlatDarkLaf");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    SwingUtilities.updateComponentTreeUI(this);
}
